package org.demo.hbase.tools;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.demo.hbase.config.FusionHBaseProperties;

public class HBaseTools {

	public static Connection getConnection() {
		Connection connection = null;
		try {
			FusionHBaseProperties fusionHBaseProperties = SpringBeanTool.getBean(FusionHBaseProperties.class);
			Configuration conf = HBaseConfiguration.create();
			conf.set("hbase.zookeeper.quorum", fusionHBaseProperties.getUrl());
			conf.set("hbase.zookeeper.property.clientPort", fusionHBaseProperties.getPort());
			connection = ConnectionFactory.createConnection(conf);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return connection;
	}

	public static Admin getAdmin() {
		Admin admin = null;
		try {
			admin = getConnection().getAdmin();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return admin;
	}
}
